﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;

namespace DHQGHN.PM2.Models
{
    public class ChiTieuModel
    {
        public int ChiTieuId { get; set; }
        [Display(Name="Cấp")]
        [Required(ErrorMessage = "Chưa chọn cấp chỉ tiêu")]
        public int Cap { get; set; }
        public string Ma { get; set; }
        public string MaCap1 { get; set; }
        public string MaCap2 { get; set; }
        public string MaCap3 { get; set; }
        [Display(Name="Tên chỉ tiêu")]
        [Required(ErrorMessage="Chưa nhập tên chỉ tiêu")]
        public string TenChiTieu { get; set; }
        [Display(Name = "Chỉ tiêu cấp 1")]
        [Required(ErrorMessage = "Chưa chọn chỉ tiêu cấp 1")]
        public string TenChiTieuCap1 { get; set; }
        [Required(ErrorMessage = "Chưa chọn chỉ tiêu cấp 2")]
        [Display(Name = "Chỉ tiêu cấp 2")]
        public string TenChiTieuCap2 { get; set; }
        public string TenChiTieuCap3 { get; set; }
        [Display(Name = "Ghi chú")]
        public string GhiChu { get; set; }
        public int Deleted { get; set; }
        public int StartDate { get; set; }
        public int EndDate { get; set; }
        public DateTime LastUpdated { get; set; }
        public int Type { get; set; }
        [Display(Name = "Đơn vị tính")]
        [Required(ErrorMessage="Chưa nhập đơn vị tính")]
        public string DonViTinh { get; set; }
        [Display(Name = "Chỉ tiêu ảo")]
        public int LaChiTieuAo { get; set; }
        [Display(Name = "Cho phép tính tổng")]
        public int ChoPhepTinhTong { get; set;}
        public int DonViId { get; set; }
        public int RecordCount { get; set; }
        public ChiTieuModel()
        {
            ChiTieuId = 0;
            Ma = string.Empty;
            MaCap1 = string.Empty;
            Cap = 0;
            LaChiTieuAo = 0;
            ChoPhepTinhTong = 1;
        }
        public ChiTieuModel(DAL.Models.DHQG.ChiTieu model)
        {
            this.ChiTieuId = model.CHI_TIEU_ID;
            this.Deleted = model.DELETED;
            this.EndDate = model.END_DATE;
            this.GhiChu = model.GHI_CHU;
            this.LastUpdated = model.LAST_UPDATED;
            this.Cap = model.CAP;
            this.Ma = model.MA;
            this.MaCap1 = model.MA_CAP1;
            this.MaCap2 = model.MA_CAP2;
            this.MaCap3 = model.MA_CAP3;
            this.TenChiTieu = model.TEN_CHI_TIEU;
            this.TenChiTieuCap1 = model.TEN_CHI_TIEU_CAP1;
            this.TenChiTieuCap2 = model.TEN_CHI_TIEU_CAP2;
            this.TenChiTieuCap3 = model.TEN_CHI_TIEU_CAP3;
            this.Type = model.TYPE;
            this.LaChiTieuAo = model.LA_CHI_TIEU_AO;
            this.ChoPhepTinhTong = model.CHO_PHEP_TINH_TONG;
            this.DonViId = model.DON_VI_ID;
            this.DonViTinh = model.DON_VI_TINH;
            this.RecordCount = model.RECORD_COUNT;
        }

        public DAL.Models.DHQG.ChiTieu ToDALModel()
        {
            DAL.Models.DHQG.ChiTieu model = new DAL.Models.DHQG.ChiTieu();

            model.CHI_TIEU_ID = this.ChiTieuId;
            model.DELETED = this.Deleted;
            model.END_DATE = this.EndDate;
            model.GHI_CHU = this.GhiChu;
            model.LAST_UPDATED = this.LastUpdated;
            model.MA = this.Ma;
            model.CAP = this.Cap;
            model.MA_CAP1 = this.MaCap1;
            model.MA_CAP2 = this.MaCap2;
            model.MA_CAP3 = this.MaCap3;
            model.TEN_CHI_TIEU = this.TenChiTieu;
            model.TEN_CHI_TIEU_CAP1 = this.TenChiTieuCap1;
            model.TEN_CHI_TIEU_CAP2 = this.TenChiTieuCap2;
            model.TEN_CHI_TIEU_CAP3 = this.TenChiTieuCap3;
            model.TYPE = this.Type;
            model.DON_VI_TINH = this.DonViTinh;
            model.LA_CHI_TIEU_AO = this.LaChiTieuAo;
            model.CHO_PHEP_TINH_TONG = this.ChoPhepTinhTong;
            model.DON_VI_ID = this.DonViId;
            return model;
        }
    }
}